import { resultType } from '@/store/redurce/search';
import { Image } from 'antd-mobile';
import classnames from 'classnames';
import { useHistory } from 'react-router-dom';
// import Icon from '@/components/Icon';
import styles from './index.module.scss';
import { ArticleType } from '@/store/redurce/article';

type propsType = {
  data: resultType | ArticleType;
};
export default function ArticleItem(props: propsType) {
  const history = useHistory();
  const item = props.data;
  const { cover } = item;
  const { images = [], type } = cover || {};
  return (
    <div className={styles.root}>
      {/* t3: 三图结构 none-mt没有图片结构  */}
      <div
        className={classnames('article-content', {
          t3: type === 3,
          'none-mt': type === 0,
        })}
      >
        <h3>{item.title}</h3>
        {type !== 0 && (
          <div
            className="article-imgs"
            onClick={() => history.push('/article/' + item.art_id)}
          >
            {images.map((item, index) => {
              return (
                <div className="article-img-wrapper" key={index}>
                  {/* 使用antd的图片组件 有图片懒加载效果 */}
                  <Image src={item} fit="cover" lazy alt=""></Image>
                  {/* <img src={item} alt="" /> */}
                </div>
              );
            })}
          </div>
        )}
      </div>
      <div className={classnames('article-info', type === 0 ? 'none-mt' : '')}>
        <span>{item.aut_name}</span>
        <span>{item.comm_count}评论</span>
        <span>{item.pubdate}</span>
      </div>
    </div>
  );
}
